package com.zhouqinuan.spring.cloud.develop.framework.demo.rabbitmq.message.consumer;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Argument;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.zhouqinuan.spring.cloud.develop.framework.demo.rabbitmq.message.exchange.RabbitExchange;
import com.zhouqinuan.spring.cloud.develop.framework.demo.rabbitmq.message.queue.RabbitQueue;
import com.zhouqinuan.spring.cloud.develop.framework.demo.rabbitmq.message.routingkey.RabbitRoutingKey;
import com.zhouqinuan.spring.cloud.develop.framework.demo.rabbitmq.model.UserInfo;
import com.zhouqinuan.spring.cloud.develop.framework.rabbitmq.consumer.AbstractMessageConsumer;

import lombok.extern.slf4j.Slf4j;

@RabbitListener(
        bindings = {
            @QueueBinding(
                exchange = @Exchange(value = RabbitExchange.USER_MESSAGE_EXCHANGE_DIRECT_DELAY, type = ExchangeTypes.DIRECT, durable = "false", autoDelete = "true", delayed = "true"/*声明为延迟exchange*/),
                value = @Queue(value = RabbitQueue.USER_MESSAGE_QUEUE_DELAY, durable = "false", autoDelete = "true"),
                key = {RabbitRoutingKey.USER_MESSAGE_ROUTING_KEY_DELAY},
                ignoreDeclarationExceptions = "true",
                arguments = @Argument(name = "x-message-ttl", value = "120000", type = "java.lang.Integer")
            )
        }
    )
@Component
@Slf4j
public class UserDelayMessageConsumer extends AbstractMessageConsumer<UserInfo> {
    
    @Override
    protected void onProcessMessage(UserInfo entity, Message message) throws Exception {
        log.info("UserDelayMessageConsumer onProcessMessage");
    }

    @Override
    protected int getMaxRetryTime() {
        return 10000;
    }
}
